package com.xw.childhealth.controller;

import com.xw.childhealth.entity.form.AdminLoginForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Description:
 * @Author: y
 * @CreateDate: 2019-11-06 09:18
 * @Version: 1.0
 */
@RequestMapping("/admin")
@Controller
@Slf4j
public class AdminUserController {


    @PostMapping("/login")
    @ResponseBody
    public ModelAndView login() {
//        System.out.println("1");
//        if (bindingResult.hasErrors()) {
//            log.error("【登陆】参数不正确, AdminLoginForm={}", form);
////            return ResultVOUtil.error(bindingResult.getFieldError().getDefaultMessage());
//        }

        //1 去数据库里的数据匹配
//        Merchant result = merchantService.findByUserNameAndPwd(merchant.getUsername(), merchant.getPwd());
//        if (result == null) {
//            return ResultVOUtil.error(ResultEnum.USERNAME_PWD_ERR);
//        }
//        //2 设置token至redis
//        String token = UUID.randomUUID().toString();
//        Integer expire = RedisConstant.EXPIRE;
//        redisTemplate.opsForValue().set(String.format(RedisConstant.TOKEN_PREFIX, token), result.getId().toString(), expire, TimeUnit.SECONDS);
//        //3 设置token至cookie
//        CookieUtil.set(response, CookieConstant.TOKEN, token, expire);
        return new ModelAndView("/pages/admin/index");
//        return ResultVOUtil.success(null);
    }

}
